import { readFileSync } from 'fs';
import * as yaml from 'js-yaml';
import { join } from 'path';

const configFileNameObj = {
  development: 'dev',
  test: 'test',
  production: 'prod',
} as Record<string, any>;

const env = process.env.NODE_ENV as string;

console.log('-env-', env);
// console.log('-process.cwd()-', process.cwd());
// console.log('-__dirname-', __dirname);

const filePath = `${__dirname}`.replace(/(\\src\\config)/, '');
// console.log('-filePath-', filePath);
export default () => {
  return yaml.load(
    // readFileSync(join(__dirname, `./${configFileNameObj[env]}.yml`), 'utf8'),
    readFileSync(
      join(filePath, `./config/${configFileNameObj[env]}.yml`),
      'utf8',
    ),
  ) as Record<string, any>;
};
